// 购物车页面渲染功能
function Render(){}
$.extend(Render.prototype,{
    init:function(){
        this.list = localStorage.getItem("carts") //是用的localStorage存储的
        if(this.list == null){
            return false
        }else{
            $(".c_null").addClass(" hide");
            $(".bc_num").removeClass("hide");
            $(".bc_bottom").removeClass("hide");
            $(".shows").removeClass("hide");
           var list = this.getdata();
           this.render(list)
        }
    },
    getdata : function(){
        var list = JSON.parse(this.list);
        return list;
    },
    render : function(list){
        var html = "";
        $.each(list,$.proxy(function(index,item){
            var count_prc = item.count * item.data.price;
            html += `
            <tr>
                <td width="57" class="c_item"><a href="javascript: ;"></a></td>
                <td width="148" class="c_img">
                    <a href="../html/goods.html#${item.id}">
                        <img src="${item.data.pathimg}" alt="">
                    </a>
                </td>
                <td width="257" class="c_title">
                    <a href="../html/goods.html#${item.id}">${item.data.title}</a>
                    <div class="bc_service">
                        <a href="#" class="bc_dd">
                            <img src="https://m1.lefile.cn/trade/cn/pc/images/base/lenovo_icon.jpg" alt="">
                            &nbsp; 购买联想服务
                        </a>
                    </div>
                </td>
                <td width="163"></td>
                <td width="152" class="one_price">
                    <span class="c_price">${item.data.price}.00</span>
                </td>
                <td width="152" class="numss">
                    <label class="i_box clear ">
                        <input type="button" value="-" class="c_reduce">
                        <input type="text" value="${item.count}" class="c_num" data-id = "${item.id}">
                        <input type="button" value="+" class="c_add">
                    </label>
                </td>
                <td width="152" class="c_red sumss">${count_prc}.00</td>
                <td width="117">
                    <a href="#;" class="removess" data-id = "${item.id}">删除</a>
                </td>
            </tr>
            `
        },this))
        $(".shows tbody").html(html);
    }
})
export default new Render();